package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.MyServiceDetails;
import com.ruoyi.system.api.domain.ServiceDetails;
import com.ruoyi.system.api.service.IPlanDetailsService;
import com.ruoyi.system.api.service.IServiceDetailsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName PlanDetailsController
 * @Description: 工程师FSE计划详情
 * @Author shihx
 * @Date 2020/2/24
 * @Version V1.0
 **/
@Api(tags="工程师FSE计划详情")
@Controller
@RequestMapping("/api/cc/ServiceDetails")
public class ServiceDetailsController extends BaseController {

    @Autowired
    private IServiceDetailsService serviceDetailsService;

    private static final Logger log = LoggerFactory.getLogger(ServiceDetailsController.class);


    /**
     * 查询工程师FSE计划详情
     * @methodName: selectServiceDetailsList
     * @description: TODO
     * @param serviceNo
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月9日17:48:41
    **/
    @GetMapping("/selectServiceDetailsList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询工程师FSE计划详情", httpMethod = "GET", notes = "查询工程师FSE计划详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectServiceDetailsList(@RequestParam(value="serviceNo",required=true) String serviceNo){
        try {
            ServiceDetails serviceDetails = new ServiceDetails();
            serviceDetails.setServiceNo(serviceNo);
            List<ServiceDetails> list = serviceDetailsService.selectServiceDetailsList(serviceDetails);
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查询服务单下实习人员列表
     *
     * @param serviceNo
     * @param fseName
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/23 3:56 下午
     */
    @GetMapping("/selectTrainPeople")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询服务单下实习人员列表", httpMethod = "GET", notes = "查询服务单下实习人员列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师姓名", name = "fseName", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectTrainPeople(@RequestParam(value="serviceNo") String serviceNo, @RequestParam(value="fseName", required = false) String fseName) {
        try {
            List<ServiceDetails> list = serviceDetailsService.selectTrainPeople(serviceNo, fseName);
            if (list == null) {
                list = new ArrayList<>();
            }
            return new ResponseWithData<>().success(list).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 删除工程师任务计划
     * @methodName: deleteServiceDetails
     * @description: TODO
     * @param serviceNoticeId
     * @param enginnerId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-22 19:28
    **/
    @Log(title = "删除工程师任务计划", businessType = BusinessType.DELETE)
    @GetMapping("/deleteServiceDetails")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "删除工程师任务计划", httpMethod = "GET", notes = "删除工程师任务计划")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单ID", name = "serviceNoticeId", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "sendenginnerId", required = false, defaultValue = "001", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> deleteServiceDetails(
            @RequestParam(value="serviceNoticeId",required=true) String serviceNoticeId,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="sendenginnerId",required=true) String sendenginnerId
    ){
        try {
            return serviceDetailsService.deleteServiceDetails(serviceNoticeId, enginnerId,sendenginnerId);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }




}
